package contextArgs

import (
	"context"
	"github.com/gin-gonic/gin"
	"github.com/mssola/user_agent"
)

type Device struct {
	Browser  string `json:"browser"`
	Version  string `json:"version"`
	Os       string `json:"os"`
	Platform string `json:"platform"`
	Ip       string `json:"ip"`
}

func GetDevice(ctx context.Context) *Device {
	gc := ctx.(*gin.Context)
	ua := user_agent.New(gc.Request.UserAgent())
	browserName, browserVersion := ua.Browser()
	return &Device{
		Browser:  browserName,
		Version:  browserVersion,
		Os:       ua.OS(),
		Platform: ua.Platform(),
		Ip:       gc.ClientIP(),
	}
}
